package com.mvd.app.activity;


import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.BottomMenu;
import com.kongzue.dialog.v3.TipDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.activitys.SignatureActivity;
import com.mvd.app.adapter.DiPanDongTaiAdapter;
import com.mvd.app.adapter.MyProvincesListAdapter2;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.Constants;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.SystemUtil;
import com.mvd.app.commons.Utils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.commons.VehicleCheckUtils;
import com.mvd.app.model.An_Huan_Model;
import com.mvd.app.model.CarItemEndModel;
import com.mvd.app.model.CarItemStartModel;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.CheckItemModel;
import com.mvd.app.model.Item_2Model;
import com.mvd.app.model.ItemsModel;
import com.mvd.app.model.MyChoiceModel;
import com.mvd.app.model.PictureModel;
import com.mvd.app.model.ReportedModel;
import com.mvd.app.model.UpdateCarStatusModel;
import com.mvd.app.model.VideoModel;
import com.mvd.app.model.WaiJainDataModel;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.iwgang.countuptime.CountupView;

import static com.mvd.app.application.BaseApplication.IsFirst;
import static com.mvd.app.application.BaseApplication.myChoiceModelList;
import static com.mvd.app.application.BaseApplication.mycar_checkItemlList;

/**
 *
 */
//底盘动态检验
public class DiPanDongTaiActivity extends BaseActivity implements AdapterView.OnItemClickListener {

    @BindView(R.id.title_btn_left)
    ImageButton titleBtnLeft;
    @BindView(R.id.title_btn_left_txt)
    Button titleBtnLeftTxt;
    @BindView(R.id.title_txt)
    TextView titleTxt;
    @BindView(R.id.iv_headtip)
    ImageView ivHeadtip;
    @BindView(R.id.title_btn_right_txt)
    Button titleBtnRightTxt;
    @BindView(R.id.title_btn_right)
    ImageButton titleBtnRight;

    @BindView(R.id.ac_dipan_dongtai_start)
    Button acDipanDongtaiStart;
    @BindView(R.id.ac_set_view_mm34)
    TextView acSetViewMm34;
    @BindView(R.id.ac_dipan_dongtai_wanchen)
    Button acDipanDongtaiWanchen;
    @BindView(R.id.ac_dipan_dongtai_jiance_scrollview)
    ScrollView scrollView;
    @BindView(R.id.ac_dipandongtai_btn_buhege_submit)
    Button acDipandongtaiBtnBuhegeSubmit;


    @BindView(R.id.ac_dipan_dongtai_tv_jishiqi)
    TextView acDipanDongtaiTvJiShiQi;
    @BindView(R.id.ac_vehicle_number)
    TextView acVehicleNumber;
    @BindView(R.id.ac_vehicle_times)
    TextView acVehicleTimes;
    @BindView(R.id.ac_vehicle_line)
    TextView acVehicleLine;
    @BindView(R.id.ac_vehicle_car_color_dipan)
    TextView acVehicleCarColorDipan;
    @BindView(R.id.textView2)
    TextView textView2;
    @BindView(R.id.ac_dipan_dongtai_jishiqi_cv_CountupViewTest3)
    CountupView acDipanDongtaiJishiqiCvCountupViewTest3;
    @BindView(R.id.ac_vehicle_haopai_zhonglei)
    TextView acVehicleHaopaiZhonglei;
    @BindView(R.id.ac_vehicle_cheliangleixing)
    TextView acVehicleCheliangleixing;
    @BindView(R.id.ac_vehicle_vin)
    TextView acVehicleVin;
    @BindView(R.id.ac_vehicle_jianyan_liushui)
    TextView acVehicleJianyanLiushui;
    @BindView(R.id.ac_vehicle_dongtai_xianhao)
    TextView acVehicleDongtaiXianhao;

    @BindView(R.id.ac_dipan_zhuan_dong_liang)
    EditText acDipanZhuanDongLiang;
    @BindView(R.id.ac_dipan_desc)
    EditText acDipanDesc;
    @BindView(R.id.ac_vehicle_dongtai_hege)
    TextView acVehicleDongtaiHege;
    @BindView(R.id.ac_dipandongtai_btn_sign)
    Button acDipandongtaiBtnSign;
    @BindView(R.id.ac_dipan_dongtai_start_img)
    Button acDipanDongtaiStartImg;
    @BindView(R.id.ac_dipan_dongtai_jieshu_img)
    Button acDipanDongtaiJieshuImg;
    @BindView(R.id.ac_dipan_dongtai_rl_img)
    RelativeLayout acDipanDongtaiRlImg;


    private CarsInforModel carsInforModel;
    private String carNo = null;//车牌号码
    private String PlateType = null;//号牌种类类型
    private String cartype = null;//车辆类型
    private DiPanDongTaiActivity instances = null;
    private int CHECK_MODE = 2;//检测模式 0:外检  1：路试 2：底盘动态
    private String Line = "1";//外检车道
    private String Item_Code = "DC";//F1外检,R1路试，DC底盘动态
    private WaiJainDataModel waiJainDataModel = new WaiJainDataModel();//上传数据model
    private VideoModel model = new VideoModel();
    boolean START = true;
    CountupView mCvCountupViewTest1;
    private String dipan_end_time = "", Login_name, login_IDNumber;
    int gotoTakePhotoCounts = 0;//结束拍照接口调用次数
    private An_Huan_Model an_huan_model;
    private int Is_An_Huan = 0;// 0:安检  1：环保  2:两者都有
    String zhuan_dong_liang = "", desc = "";
    String dongtai_hege = "";

    String upload_code_str = "", upload_code_str_500 = "";
    List<MyChoiceModel> myChoiceModelList_waijian = new ArrayList<>();//Code2选择的列表
    boolean is_500 = false;
    boolean isSign = false;//是否已签名

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_di_pan_dong_tai);
        ButterKnife.bind(this);
        setBackBtn();
        setTopTitle(R.string.ac_dipan_dongtai_title);
        pop_xuhao();
        instances = this;
        String logStr = "\n" + "===手机信息===" + "\n" + "手机厂商===" + SystemUtil.getDeviceBrand() +
                "\n" + "手机型号===" + SystemUtil.getSystemModel() + "\n" + "系统版本号===" + SystemUtil.getSystemVersion();
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        String logStrf = "\n" + "onCreate-----底盘动态-------" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
        an_huan_model = (An_Huan_Model) getIntent().getSerializableExtra("model_CarsInforModel");
        Is_An_Huan = an_huan_model.getIsAnHuan();
//        carsInforModel = getIntent().getExtras().getParcelable("model_CarsInforModel");
        Login_name = getIntent().getExtras().getString("Login_name", "");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        if (Is_An_Huan == 0 || Is_An_Huan == 2) {
            carsInforModel = an_huan_model.getCarsInforModel();
            initView();

            mCvCountupViewTest1 = (CountupView) findViewById(R.id.ac_dipan_dongtai_jishiqi_cv_CountupViewTest3);

            if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
                myChoiceModelList.clear();
            }
            List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
            Item_2Model item_2 = null;
            for (int i = 0; i < BaseApplication.checkItemModelList.size(); i++) {
                item_2 = new Item_2Model();
                item_2.setID(BaseApplication.checkItemModelList.get(i).getID());
                item_2.setCode1(BaseApplication.checkItemModelList.get(i).getCode1());
                item_2.setCode2(BaseApplication.checkItemModelList.get(i).getCode2());
                item_2.setName2(BaseApplication.checkItemModelList.get(i).getName2());
                Item_2Model_list.add(item_2);
            }
            for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                    if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k).getCode2())) {
                        Item_2Model_list.remove(j);
                    }
                }
            }
            if (IsFirst) {
                for (int i = 0; i < Item_2Model_list.size(); i++) {
//                UtilsLog.e("dipandongtai-Item_2Model_list=11=" + Item_2Model_list.get(i).toString());
                    MyChoiceModel model = new MyChoiceModel();
                    model.setCode2(Item_2Model_list.get(i).getCode2());
                    model.setChecked(true);
                    model.setName2(Item_2Model_list.get(i).getName2());
                    model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
                    model.setCode_values("0");
                    myChoiceModelList.add(model);
                }
            }

        }
        getMyCarItems();
        UtilsLog.e("dipan----ip==" + SharedPreferencesUtils.getIP(DiPanDongTaiActivity.this));
        BaseApplication.BaseApplication_buHeGeModel3List = new ArrayList<>();//不合格项目第三级
        if (SharedPreferencesUtils.getOpenSign(this)) {
            acDipandongtaiBtnSign.setVisibility(View.VISIBLE);
            isSign = false;
        } else {
            acDipandongtaiBtnSign.setVisibility(View.GONE);
            isSign = true;
        }

        if (SharedPreferencesUtils.getDongTaiImg(this)) {
            acDipanDongtaiRlImg.setVisibility(View.VISIBLE);
        } else {
            acDipanDongtaiRlImg.setVisibility(View.GONE);
        }
    }

    int recLen = 0;
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            recLen++;
            if (recLen < 120) {
                acDipanDongtaiTvJiShiQi.setText("项目进行时间：" + recLen + "  秒");
            }
            handler.postDelayed(this, 1000);
        }
    };

    @Override
    protected void initView() {
        super.initView();
        if (carsInforModel != null) {
            //车牌号码
            if (!TextUtils.isEmpty(carsInforModel.getPlateRegion()) && !TextUtils.isEmpty(carsInforModel
                    .getPlateNO())) {
                carNo = carsInforModel.getPlateRegion() +
                        carsInforModel.getPlateNO()
                        + carsInforModel.getPlateExtra();
                acVehicleNumber.setText(carNo);
            }
            //号牌类型
            if (!TextUtils.isEmpty(carsInforModel.getPlateTypeName())) {
                PlateType = String.valueOf(carsInforModel.getPlateTypeName());
                acVehicleHaopaiZhonglei.setText(PlateType);
            }
            //车辆类型
            if (!TextUtils.isEmpty(carsInforModel.getType())) {
                cartype = String.valueOf(carsInforModel.getType());
                acVehicleCheliangleixing.setText(PlateType);
            }
            //检测时间
            if (!TextUtils.isEmpty(carsInforModel.getDetectDate())) {
                String str = carsInforModel.getDetectDate().substring(6, carsInforModel.getDetectDate()
                        .length() - 2).trim();
//                String DetectDate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
//                acDipanDongtaiJianceTime.setText(carsInforModel.getDetectDate());
            }

            //检验次数
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getTimes()))) {
                acVehicleTimes.setText(carsInforModel.getTimes() + "次");
            }
            //车身颜色
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getBodyColor()))) {
                acVehicleCarColorDipan.setText(VehicleCheckUtils.CarColorsFilter(carsInforModel
                        .getBodyColor()));
            }
            //vin
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getVIN()))) {
                acVehicleVin.setText(carsInforModel.getVIN());
            }
            //检验流水
            if (!TextUtils.isEmpty(String.valueOf(carsInforModel.getSN()))) {
                acVehicleJianyanLiushui.setText(carsInforModel.getSN());
            }

        }
    }

    @OnClick({R.id.ac_dipan_dongtai_start, R.id.ac_dipan_dongtai_wanchen,
            R.id.ac_dipandongtai_btn_buhege_submit, R.id.title_btn_left,
            R.id.ac_dipandongtai_btn_sign,
            R.id.ac_vehicle_line, R.id.ac_vehicle_dongtai_hege
            , R.id.ac_dipan_dongtai_start_img, R.id.ac_dipan_dongtai_jieshu_img})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_dipan_dongtai_start_img:
                PHOTO_PlatformCode = "0344";
                getDataDCPicture(PHOTO_PlatformCode, "****底盘动态start-start-start-start-start--拍照片****");
                break;
            case R.id.ac_dipan_dongtai_jieshu_img:
                PHOTO_PlatformCode = "0342";
                getDataDCPicture(PHOTO_PlatformCode, "****底盘动态end-end-end-end-end--拍照片****");
                break;
            case R.id.title_btn_left:
                //左上角返回键
//                updateCarStatusInfor_anjian(ITEM_MIDDLE_EXIT_CODE);
                String logStr = "\n" + "底盘动态--点击左上角返回键" + "\n";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                finish();
                break;
            case R.id.ac_dipandongtai_btn_buhege_submit:
                //不合格项目录入
//                Intent intent = new Intent(instances, DisqualificationActivity.class);
//                intent.putExtra("buhege_flag", 1);//不合格项目跳转 0：外检 1：底盘动态
//                intent.putExtra("WaiJianPhotoActivity_CarsInforModel", carsInforModel);
//                startActivity(intent);
                String logStr2 = "\n" + "底盘动态--不合格项目录入" + "\n";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                getMyCarItems();
                Handler handler2 = new Handler();
                handler2.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Intent intent_2 = new Intent(instances, WaiJianResultActivity.class);
                        intent_2.putExtra("WaiJianPhotoActivity_CarsInforModel", carsInforModel);
                        startActivityForResult(intent_2, 500);
                    }
                }, 400);//后执行Runnable中的run方法
//                Intent intent_2 = new Intent(instances, WaiJianResultActivity.class);
//                intent_2.putExtra("WaiJianPhotoActivity_CarsInforModel", carsInforModel);
//                startActivity(intent_2);
                break;
            case R.id.ac_vehicle_line:
                pop_xuhao.showAsDropDown(acVehicleLine);
                break;
            case R.id.ac_vehicle_dongtai_hege:
                //是否合格
                showMyDialog(Constants.HEGE_LISTS);
                break;
            case R.id.ac_dipan_dongtai_start:
                desc = acDipanDesc.getText().toString().trim();
                zhuan_dong_liang = acDipanZhuanDongLiang.getText().toString().trim();
//                mCvCountdownView.start(4 * 1000); // 毫秒
//                acDipanDongtaiStart.setClickable(false);
                //底盘动态检验开始
                PHOTO_PlatformCode = "0344";
//                takePicture();
                String logStr3 = "\n" + "底盘动态项目开始--点击项目开始按钮--未请求--PHOTO_PlatformCode==" + PHOTO_PlatformCode + "\n";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr3.getBytes());
                getData(0);
                if (SharedPreferencesUtils.getDongTaiImg(this)) {
                } else {
                    getDataDCPicture(PHOTO_PlatformCode, "****底盘动态start-start-start-start-start--拍照片****");
                }

                mCvCountupViewTest1.setTag("test1");
                long time1 = (long) 1000;
                mCvCountupViewTest1.start(time1);
//                getDataReportData();
                break;
            case R.id.ac_dipan_dongtai_wanchen:
                //底盘动态检验结束
                desc = acDipanDesc.getText().toString().trim();
                zhuan_dong_liang = acDipanZhuanDongLiang.getText().toString().trim();
                dongtai_hege = acVehicleDongtaiHege.getText().toString().trim();
//                acDipanDongtaiWanchen.setEnabled(false);
                PHOTO_PlatformCode = "0342";
                String logStr4 = "\n" + "底盘动态项目结束--点击项目结束按钮--未请求--PHOTO_PlatformCode==" + PHOTO_PlatformCode + "\n";
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr4.getBytes());
//                getDataDCPicture(PHOTO_PlatformCode, "****底盘动态end-end-end-end-end--拍照片****");

//                Handler handler = new Handler();
//                handler.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
                if (SharedPreferencesUtils.getDongTaiImg(this)) {
                    upData();
                } else {
                    getDataDCPicture(PHOTO_PlatformCode, "****底盘动态end-end-end-end-end--拍照片****");
                }

//                    }
//                }, 300);//后执行Runnable中的run方法
                //方向盘最大自由转动量

//                finish();
                break;
            case R.id.ac_dipandongtai_btn_sign:
                Intent intent3 = new Intent(instances, SignatureActivity.class);
                intent3.putExtra("sign_carsInforModel", carsInforModel);
                intent3.putExtra("line", acVehicleLine.getText().toString().trim());
                intent3.putExtra("type", 2);
                intent3.putExtra("login_w_name", Login_name);
                startActivityForResult(intent3, 678);
                break;
        }
    }

    //提交数据
    private void upData() {
        waiJainDataModel.setDCResultNote(desc);
        waiJainDataModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        waiJainDataModel.setGUID(carsInforModel.getGUID());
        waiJainDataModel.setDetectionDevID(CommonUtils.getIMEI(instances));
        waiJainDataModel.setBrakeForce(carsInforModel.getBrakeForce());
//                if (SharedPreferencesUtils.getAddress(this).equals("温州")) {
//                    waiJainDataModel.setPlateNO(carsInforModel.getPlateRegion()
//                            + carsInforModel.getPlateNO()
//                            + carsInforModel.getPlateExtra());
//                } else if (SharedPreferencesUtils.getAddress(this).equals("常山")) {
        waiJainDataModel.setPlateNO(carsInforModel.getPlateRegion()
                + carsInforModel.getPlateNO());
//                }
//                waiJainDataModel.setPlateNO(carsInforModel.getPlateRegion() +
//                        carsInforModel.getPlateNO()
//                        + carsInforModel.getPlateExtra());
        waiJainDataModel.setAirAdmission(carsInforModel.getAirAdmission());
        try {
            String name = URLDecoder.decode(Login_name, "UTF-8");
            waiJainDataModel.setDynamicInspector(name);//检测员名字，汉字
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        waiJainDataModel.setDynamicNo(login_IDNumber);

        waiJainDataModel.setApprovedLoad(carsInforModel.getApprovedLoad());
        waiJainDataModel.setArea(carsInforModel.getArea());
        waiJainDataModel.setBodyColor(carsInforModel.getBodyColor());
        waiJainDataModel.setBrand(carsInforModel.getBrand());
        waiJainDataModel.setCarBodyType(carsInforModel.getCarBodyType());
        waiJainDataModel.setCarID(carsInforModel.getCarID());
        waiJainDataModel.setCarModel(carsInforModel.getCarModel());
        waiJainDataModel.setCarTypeLevel(carsInforModel.getCarTypeLevel());
        waiJainDataModel.setCategory(carsInforModel.getCategory());
        waiJainDataModel.setCentralAxle(carsInforModel.getCentralAxle());
        waiJainDataModel.setCode(carsInforModel.getCode());
        waiJainDataModel.setCombCarNO(carsInforModel.getCombCarNO());
        waiJainDataModel.setCurbWeight(carsInforModel.getCurbWeight());
        waiJainDataModel.setDetectDate(carsInforModel.getDetectDate());
        waiJainDataModel.setDetectionCategory(carsInforModel.getDetectionCategory());
        waiJainDataModel.setDetectionStatus(carsInforModel.getDetectionStatus());
        waiJainDataModel.setDisplacement(carsInforModel.getDisplacement());
        waiJainDataModel.setDriveAxle(carsInforModel.getDriveAxle());
        waiJainDataModel.setDriverAxleWeight(carsInforModel.getDriverAxleWeight());
        waiJainDataModel.setDriverTypeName(carsInforModel.getDriverTypeName());
        waiJainDataModel.setDriverType(carsInforModel.getDriverType());
        waiJainDataModel.setPlateType(carsInforModel.getPlateType());
        waiJainDataModel.setItemcode(Item_Code);
        waiJainDataModel.setLine(Line);
        waiJainDataModel.setMainAxis(carsInforModel.getMainAxis());
        waiJainDataModel.setParkingAxle(carsInforModel.getParkingAxle());
        waiJainDataModel.setEngineNO(carsInforModel.getEngineNO());
        waiJainDataModel.setFuelType(carsInforModel.getFuelType());
        waiJainDataModel.setPlateTypeName(carsInforModel.getPlateTypeName());
        waiJainDataModel.setPlatformSN(carsInforModel.getPlatformSN());
        waiJainDataModel.setQueueID(carsInforModel.getQueueID());
        waiJainDataModel.setSN(carsInforModel.getSN());
        waiJainDataModel.setStatus(carsInforModel.getStatus());
        waiJainDataModel.setTest_times(carsInforModel.getTimes());
        waiJainDataModel.setType(carsInforModel.getType());
        waiJainDataModel.setVIN(carsInforModel.getVIN());
        waiJainDataModel.setTimes(carsInforModel.getTimes());
        waiJainDataModel.setWheelMaxTurn(zhuan_dong_liang);
        waiJainDataModel.setRemark("");
        UtilsLog.e("mCvCountupViewTest1.getMinute()===" + mCvCountupViewTest1.getMinute());
        if (isSign) {
            if (CommonUtils.isOnline(instances)) {
//                    if (1 > 0) {
//                    if (!SharedPreferencesUtils.getOpenSign(this)) {
                if (SharedPreferencesUtils.getDaChe(DiPanDongTaiActivity.this)) {
                    UtilsLog.e("dache========111111111111=====");
                    if (carsInforModel.getType().contains("M")
                            || carsInforModel.getType().contains("N")
                            ) {
                        UtilsLog.e("dache========33333333333=====");
                        //摩托车、三轮汽车
                        //上传平台的数据
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                        waiJainDataModel.setDataType("DC");
                        Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                uploadPlatformData_w(waiJainDataModel);
                            }
                        }, 600);//后执行Runnable中的run方法
                    } else {
                        UtilsLog.e("dache========444444444444444=====");
                        if (mCvCountupViewTest1.getMinute() >= 1) {
//                                upData(0);
                            //上传平台的数据
                            CommonUtils.showLoadingDialog(instances, "加载中...");
                            waiJainDataModel.setDataType("DC");
                            Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    uploadPlatformData_w(waiJainDataModel);
                                }
                            }, 600);//后执行Runnable中的run方法
                        } else {
                            Toast.makeText(DiPanDongTaiActivity.this, "时间未达60s，项目无法结束", Toast.LENGTH_LONG).show();
                        }
                    }
                } else {
                    UtilsLog.e("dache========2222222222222=====");
                    //上传平台的数据
                    CommonUtils.showLoadingDialog(instances, "加载中...");
                    waiJainDataModel.setDataType("DC");
                    Handler handler = new Handler();
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            uploadPlatformData_w(waiJainDataModel);
                        }
                    }, 600);//后执行Runnable中的run方法
                }


//                    // 哈尔滨地区要限值时间小车120秒，大车240秒
//                    if (SharedPreferencesUtils.getDaChe(DiPanDongTaiActivity.this)) {
//                        if (carsInforModel.getUseProperty().equals("A")
//                                && (carsInforModel.getType().contains("K3")
//                                || carsInforModel.getType().contains("K4"))
//                                ) {
//                            //非营运小型微型载客汽车--xiaoche
//                            if (mCvCountupViewTest1.getMinute() >= 2) {
////                                upData(0);
//                                //上传平台的数据
//                                CommonUtils.showLoadingDialog(instances, "加载中...");
//                                waiJainDataModel.setDataType("DC");
//                                Handler handler = new Handler();
//                                handler.postDelayed(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        uploadPlatformData_w(waiJainDataModel);
//                                    }
//                                }, 600);//后执行Runnable中的run方法
//                            } else {
//                                Toast.makeText(DiPanDongTaiActivity.this, "时间未达120s，项目无法结束", Toast.LENGTH_LONG).show();
//                            }
//                        } else if (carsInforModel.getType().contains("M")
//                                || carsInforModel.getType().contains("N")
//                                ) {
//                            //摩托车、三轮汽车
//                            if (mCvCountupViewTest1.getSecond() >= 1) {
////                                upData(0);
//                                //上传平台的数据
//                                CommonUtils.showLoadingDialog(instances, "加载中...");
//                                waiJainDataModel.setDataType("DC");
//                                Handler handler = new Handler();
//                                handler.postDelayed(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        uploadPlatformData_w(waiJainDataModel);
//                                    }
//                                }, 600);//后执行Runnable中的run方法
//                            } else {
//                                Toast.makeText(DiPanDongTaiActivity.this, "时间未达90s，项目无法结束", Toast.LENGTH_LONG).show();
//                            }
//                        } else {
//                            //大车
//                            if (mCvCountupViewTest1.getMinute() >= 4) {
////                                upData(0);
//                                //上传平台的数据
//                                CommonUtils.showLoadingDialog(instances, "加载中...");
//                                waiJainDataModel.setDataType("DC");
//                                Handler handler = new Handler();
//                                handler.postDelayed(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        uploadPlatformData_w(waiJainDataModel);
//                                    }
//                                }, 600);//后执行Runnable中的run方法
//                            } else {
//                                Toast.makeText(DiPanDongTaiActivity.this, "时间未达240s，项目无法结束", Toast.LENGTH_LONG).show();
//                            }
//                        }
//                    } else {
////                        upData(0);
//                        //上传平台的数据
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
//                        waiJainDataModel.setDataType("DC");
//                        Handler handler = new Handler();
//                        handler.postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//                                uploadPlatformData_w(waiJainDataModel);
//                            }
//                        }, 600);//后执行Runnable中的run方法
//                    }

//                        //上传平台的数据
//                        waiJainDataModel.setDataType("DC");
//                        Handler handler = new Handler();
//                        handler.postDelayed(new Runnable() {
//                            @Override
//                            public void run() {
//                                uploadPlatformData_w(waiJainDataModel);
//                            }
//                        }, 600);//后执行Runnable中的run方法

//                    model.setItemcode(Item_Code);
//                    model.setLine(Line);
//                    model.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
//                    model.setPlateType(carsInforModel.getPlateType());
//                    model.setPlatformSN(carsInforModel.getPlatformSN());
//                    model.setTest_times(carsInforModel.getTimes());
//                    model.setDetectionItemStartDate(BaseApplication.D_ItemStart_time);
//                    model.setDetectionItemEndDate(BaseApplication.D_ItemEnd_time);
////                    model.setDetectionItemEndDate(dipan_end_time);
//                    model.setDetectionID(String.valueOf(carsInforModel.getID()));

                START = false;
                //视频接口上传数据
//                    uploadVideo(model);
//                    } else {
//                        Intent intent3 = new Intent(instances, SignatureActivity.class);
//                        intent3.putExtra("sign_carsInforModel", carsInforModel);
//                        intent3.putExtra("line", acVehicleLine.getText().toString().trim());
//                        intent3.putExtra("type", 2);
//                        startActivityForResult(intent3, 678);
//                    }
            } else {
                Toast.makeText(instances, getResources().getString(R.string.network_error), Toast
                        .LENGTH_LONG).show();
            }
        } else {
//                        Intent intent3 = new Intent(instances, SignatureActivity.class);
//                        intent3.putExtra("sign_carsInforModel", carsInforModel);
//                        intent3.putExtra("line", acVehicleLine.getText().toString().trim());
//                        intent3.putExtra("type",3);
//                        startActivityForResult(intent3, 678);
            TipDialog.show(instances, "还未进行签名", TipDialog.TYPE.WARNING);
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        DiPanDongTaiAdapter.ViewHolder vHollder = (DiPanDongTaiAdapter.ViewHolder) view.getTag();
        //在每次获取点击的item时将对于的checkbox状态改变，同时修改map的值。
        vHollder.cBox.toggle();
        DiPanDongTaiAdapter.isSelected.put(position, vHollder.cBox.isChecked());
    }

    //    View.OnClickListener bPop = new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//            for (int i = 0; i < acDipanDongtaiStartListview.getCount(); i++) {
//                if (DiPanDongTaiAdapter.isSelected.get(i)) {
//                    DiPanDongTaiAdapter.ViewHolder vHollder = (DiPanDongTaiAdapter.ViewHolder)
// acDipanDongtaiStartListview.getChildAt(i).getTag();
//                    UtilsLog.d("--onClick --" + vHollder.title.getText());
//                }
//            }
//        }
//    };
    //popuwindow
    private View popu_xuhao_view;
    private LinearLayout parent22;
    private PopupWindow pop_xuhao = null;
    private ListView listview_xuhao;
    private MyProvincesListAdapter2 myProAdapter;
    private List<String> xuhaoList = new ArrayList<String>();

    private void pop_xuhao() {
        for (int i = 0; i < Constants.WAIJIAN_CHEDAO_CHEJIAN_XIANHAO2.length; i++) {
            xuhaoList.add(i, Constants.WAIJIAN_CHEDAO_CHEJIAN_XIANHAO2[i]);
        }
        pop_xuhao = new PopupWindow(this);
        popu_xuhao_view = getLayoutInflater().inflate(R.layout.item_setting_province_letter,
                null);
        pop_xuhao.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_xuhao.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        pop_xuhao.setBackgroundDrawable(new BitmapDrawable());
        pop_xuhao.setFocusable(true);
        pop_xuhao.setOutsideTouchable(true);
        pop_xuhao.setContentView(popu_xuhao_view);
        parent22 = (LinearLayout) popu_xuhao_view.findViewById(R.id.setting_provinces_parent);
        listview_xuhao = (ListView) popu_xuhao_view.findViewById(R.id.setting_provinces_listview2);
        myProAdapter = new MyProvincesListAdapter2(this, xuhaoList);
        listview_xuhao.setAdapter(myProAdapter);
        listview_xuhao.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,
                                    int position, long arg3) {
                acVehicleLine.setText(xuhaoList.get(position));
                Line = xuhaoList.get(position);
                pop_xuhao.dismiss();
            }
        });
        parent22.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                pop_xuhao.dismiss();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OkGo.getInstance().cancelTag(this);
//        Toast.makeText(instances, "检测完成", Toast.LENGTH_LONG).show();
        CommonUtils.hideLoadingDialog(this);
        instances = null;
        String logStrf = "\n" + "onDestroy-----底盘动态-------" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
    }

    private void getData(int flag) {
        if (!TextUtils.isEmpty(SharedPreferencesUtils.getIP(instances))) {
            if (CommonUtils.isOnline(instances)) {
//                getDataReportData();
                switch (flag) {
                    case 0:
                        getDataWaiJainStart();
                        break;
                    case 1:
                        getDataWaiJainEnd();
                        break;
                }
            } else {
                Toast.makeText(instances, getResources().getString(R.string.network_error), Toast
                        .LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(instances, "请设置IP与端口号", Toast.LENGTH_LONG).show();
        }
    }

    //动态拍照
    String jsonStr_getDataDCPicture;

    private void getDataDCPicture(String plateType, final String statemeng) {
        String logStr = "\n" + "------底盘动态--拍照请求接口调用-----" + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        PictureModel model = new PictureModel();
        model.setItemCode(Item_Code);
        model.setLine(Line);
        model.setGUID(carsInforModel.getGUID());
        model.setPhotoDate(DateUtil.currentTime2());
        model.setPhotoType(plateType);
//        if (SharedPreferencesUtils.getAddress(DiPanDongTaiActivity.this).equals("温州")) {
//            model.setPlateNO(carsInforModel.getPlateRegion()
//                    + carsInforModel.getPlateNO()
//                    + carsInforModel.getPlateExtra());
//        } else if (SharedPreferencesUtils.getAddress(DiPanDongTaiActivity.this).equals("常山")) {
        model.setPlateNO(carsInforModel.getPlateRegion()
                + carsInforModel.getPlateNO());
//        }
//        model.setPlateNO(carsInforModel.getPlateRegion() +
//                carsInforModel.getPlateNO()
//                + carsInforModel.getPlateExtra());
        model.setPlatformSN(carsInforModel.getPlatformSN());
        model.setTest_times(carsInforModel.getTimes());
        model.setTimes(carsInforModel.getTimes());
        model.setVIN(carsInforModel.getVIN());
        model.setPlateType(carsInforModel.getPlateType());
        model.setDetection_ID(String.valueOf(carsInforModel.getID()));
        Gson gson = new Gson();
        jsonStr_getDataDCPicture = gson.toJson(model);
        UtilsLog.e("getDataDCPicture---jsonStr==" + jsonStr_getDataDCPicture);
        String url_ip = "";
        if (!TextUtils.isEmpty(SharedPreferencesUtils.getIP(DiPanDongTaiActivity.this)) && SharedPreferencesUtils.getIP(DiPanDongTaiActivity.this) != "") {
            url_ip = SharedPreferencesUtils.getIP(DiPanDongTaiActivity.this);
        } else {

        }

        UtilsLog.e("getDataDCPicture---url==" + url_ip + DC_PICTURE);
        OkGo.<String>post(url_ip + DC_PICTURE).tag(DiPanDongTaiActivity.this)
                .upJson(jsonStr_getDataDCPicture)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataDCPicture-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getDataDCPicture-newResult==" + newResult);
                        String logStr = "\n" + "底盘动态--拍照请求成功==" + statemeng + "==" +
                                "\n" + "URL::" + DC_PICTURE +
                                "\n" + "JSON::" + jsonStr_getDataDCPicture + "\n" +
                                "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            if ("ok".equals(result) || "ok".equals(newResult)) {
                                if (SharedPreferencesUtils.getDongTaiImg(instances)) {
                                    Toast.makeText(instances, "拍照成功", Toast.LENGTH_LONG)
                                            .show();
                                } else {
                                    if (statemeng.contains("end")) {
                                        upData();
                                    }
                                }
                                String logStr2 = "\n" + "底盘动态--拍照请求成功=OK--OK--OK" +
                                        "\n" + "JSON::" + jsonStr_getDataDCPicture + "\n" +
                                        "result::" + result;
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                            } else {
                                if (gotoTakePhotoCounts < 3) {
                                    String logStr2 = "\n" + "底盘动态--拍照请求成功=循环=" +
                                            "\n" + "第" + gotoTakePhotoCounts + "次" + "\n" + "JSON::" +
                                            jsonStr_getDataDCPicture + "\n" + "result::" + result;
                                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                    getDataDCPicture(PHOTO_PlatformCode, "****底盘动态end-end-end-end-end--拍照片****");
                                    gotoTakePhotoCounts++;
                                } else {
                                    String logStr2 = "\n" + "底盘动态--拍照请求成功=循环三次请求失败--没治了=" +
                                            "\n" + "JSON::" + jsonStr_getDataDCPicture + "\n" +
                                            "result::" + result;
                                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                                }
                            }
                        } else {
                            UtilsLog.e("getDataDCPicture-result==" + "没有数据");
                        }
//                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataDCPicture-onError==" + response.body());
                        String logStr = "\n" + "底盘动态--拍照请求失败" +
                                "\n" + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //底盘动态开始
    String upjson_url_start_item_dipan;

    private void getDataWaiJainStart() {
        CarItemStartModel carItemStartModel = new CarItemStartModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
//        carItemStartModel.setPlateNO(carsInforModel.getPlateNO());
//        if (SharedPreferencesUtils.getAddress(this).equals("温州")) {
//            carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
//                    + carsInforModel.getPlateNO()
//                    + carsInforModel.getPlateExtra());
//        } else if (SharedPreferencesUtils.getAddress(this).equals("常山")) {
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
                + carsInforModel.getPlateNO());
//        }
//        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
//                + carsInforModel.getPlateNO()
//                + carsInforModel.getPlateExtra());
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setDetectionID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setLine(Line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID("");
        carItemStartModel.setItemCode(Item_Code);
        BaseApplication.D_ItemStart_time = "";
        BaseApplication.D_ItemStart_time = DateUtil.currentTime2();
        carItemStartModel.setDetectionItemStartDate(BaseApplication.D_ItemStart_time);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);
        upjson_url_start_item_dipan = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";
        String logStr = "\n" + "底盘动态开始--json" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                ITEM_END + "\n" + "JSON::" + upjson_url_start_item_dipan +
                "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataWaiJainStart---jsonStr==" + upjson_url_start_item_dipan);
        UtilsLog.e("getDataWaiJainStart---url==" + SharedPreferencesUtils.getIP(this) + ITEM_START);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_START)
                .tag(this)
                .upJson(upjson_url_start_item_dipan)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataWaiJainStart-result==" + result);
                        CommonUtils.hideLoadingDialog(instances);
                        String str = result.substring(1, result.length() - 1);
                        String logStr = "\n" + "底盘动态开始--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_START + "\n" + "JSON::" + upjson_url_start_item_dipan +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication
                                .JIANCE_MODE, logStr.getBytes());

                        if ("ok".equals(str)) {
                            handler.postDelayed(runnable, 1000);
                            Toast.makeText(instances, "项目开始", Toast.LENGTH_SHORT)
                                    .show();


//                            updateCarStatusInfor_anjian(1);
//                            getDataReportData();
                        } else {
//                            String logStr = "\n" + "底盘动态开始--上线失败" +
//                                    "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
//                                    ITEM_END + "\n" + "JSON::" + upjson_url_start_item_dipan +
//                                    "\n" + "result::" + result;
//                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                            Toast.makeText(instances, "上线失败，请重试", Toast.LENGTH_LONG)
                                    .show();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataWaiJainStart-onError==" + response.body());
                        String logStr = "\n" + "底盘动态开始--失败" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    /**
     * 更新车辆状态
     *
     * @param flag flag:0 未检测
     * flag:1 项目开始
     * flag:2 项目结束
     * flag:99  中途退出的情况
     */
    String jsonStr_updateCarStatusInfor;

    private void updateCarStatusInfor(int flag) {
        UpdateCarStatusModel model = new UpdateCarStatusModel();
        model.setType(0);
        model.setDynamicInspector(Login_name);
        model.setQueueID(String.valueOf(carsInforModel.getID()));
        switch (CHECK_MODE) {
            case 0:
                model.setAppearanceStatus(flag);
                break;
            case 1:
                model.setRoadStatus(flag);
                break;
            case 2:
                model.setDynamicStatus(flag);
                break;
        }
        Gson gson = new Gson();
        jsonStr_updateCarStatusInfor = gson.toJson(model);
        UtilsLog.e("updateCarStatusInfor_anjian---jsonStr==" + jsonStr_updateCarStatusInfor);
        UtilsLog.e("updateCarStatusInfor_anjian---url==" + SharedPreferencesUtils.getIP(this) + UPDATE_CAR_STATUS);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + UPDATE_CAR_STATUS)
                .tag(this)
                .upJson(jsonStr_updateCarStatusInfor)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body().trim();
                        UtilsLog.e("updateCarStatusInfor_anjian-result==" + result);
                        UtilsLog.e("updateCarStatusInfor_anjian-result=22=" + result.substring(1, result.length() -
                                1));
                        String logStr = "\n" + "底盘动态--更新状态--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPDATE_CAR_STATUS +
                                "\n" + "JSON::" + jsonStr_updateCarStatusInfor +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication
                                .JIANCE_MODE, logStr.getBytes());
//                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        String logStr = "\n" + "底盘动态--更新状态--失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                UPDATE_CAR_STATUS +
                                "\n" + "JSON::" + jsonStr_updateCarStatusInfor +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication
                                .JIANCE_MODE, logStr.getBytes());
                        UtilsLog.e("getDataWaiJainStart-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //外检检测结束
    String upjson_url_getDataWaiJainEnd;

    private void getDataWaiJainEnd() {
        CarItemEndModel carItemStartModel = new CarItemEndModel();
        carItemStartModel.setPlatformSN(carsInforModel.getPlatformSN());
        carItemStartModel.setPlateType(carsInforModel.getPlateType());
//        if (SharedPreferencesUtils.getAddress(this).equals("温州")) {
//            carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
//                    + carsInforModel.getPlateNO()
//                    + carsInforModel.getPlateExtra());
//        } else if (SharedPreferencesUtils.getAddress(this).equals("常山")) {
        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
                + carsInforModel.getPlateNO());
//        }
//        carItemStartModel.setPlateNO(carsInforModel.getPlateRegion()
//                + carsInforModel.getPlateNO()
//                + carsInforModel.getPlateExtra());
        carItemStartModel.setVIN(carsInforModel.getVIN());
        carItemStartModel.setLine(Line);
        carItemStartModel.setTest_times(carsInforModel.getTimes());
        carItemStartModel.setDetectionDevID("");
        carItemStartModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
        carItemStartModel.setItemCode(Item_Code);
        BaseApplication.D_ItemEnd_time = "";
        BaseApplication.D_ItemEnd_time = DateUtil.currentTime2();
        dipan_end_time = BaseApplication.D_ItemEnd_time;
        carItemStartModel.setDetectionItemEndDate(BaseApplication.D_ItemEnd_time);
        UtilsLog.e("getDataWaiJainEnd---D_ItemEnd_time==" + BaseApplication.D_ItemEnd_time);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(carItemStartModel);
        upjson_url_getDataWaiJainEnd = "{" + jsonStr.substring(1, jsonStr.length() - 1) + "}";

        String logStr = "\n" + "底盘动态结束--JSON" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                ITEM_END + "\n" + "JSON::" + upjson_url_getDataWaiJainEnd + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("getDataWaiJainEnd---jsonStr==" + upjson_url_getDataWaiJainEnd);
        UtilsLog.e("getDataWaiJainEnd---url==" + SharedPreferencesUtils.getIP(this) + ITEM_END);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + ITEM_END).tag(this)
                .upJson(upjson_url_getDataWaiJainEnd)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("底盘动态结束-result==" + result);
                        String str = result.substring(1, result.length() - 1);
                        String logStr = "\n" + "底盘动态结束--请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_END + "\n" + "JSON::" + upjson_url_getDataWaiJainEnd + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if ("ok".equals(str)) {
                            WaiJainDataModel waiJainDataModel2 = new WaiJainDataModel();
                            waiJainDataModel2.setDetection_ID(String.valueOf(carsInforModel.getID()));
                            waiJainDataModel2.setGUID(carsInforModel.getGUID());
                            waiJainDataModel2.setWheelMaxTurn(zhuan_dong_liang);
                            waiJainDataModel2.setTimes(carsInforModel.getTimes());
                            waiJainDataModel2.setWheelVerdict(dongtai_hege);
//                            waiJainDataModel2.setWheelVerdict("");
                            waiJainDataModel2.setWheelStandard("");
                            waiJainDataModel2.setStart_Time(BaseApplication.D_ItemStart_time);
                            waiJainDataModel2.setFinish_Time(BaseApplication.D_ItemEnd_time);
                            uploadData(waiJainDataModel2);

//                            getDataReportData("DC");

//                            Toast.makeText(instances, "项目完成", Toast.LENGTH_LONG).show();
                            //项目总结束

                            updateCarStatusInfor(1);

                            acDipanDongtaiWanchen.setEnabled(true);

                            model.setItemcode(Item_Code);
                            model.setLine(Line);
                            model.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
                            model.setPlateType(carsInforModel.getPlateType());
                            model.setPlatformSN(carsInforModel.getPlatformSN());
                            model.setTest_times(carsInforModel.getTimes());
                            model.setDetectionItemStartDate(BaseApplication.D_ItemStart_time);
                            model.setDetectionItemEndDate(BaseApplication.D_ItemEnd_time);
                            model.setDetectionID(String.valueOf(carsInforModel.getID()));

                            //视频接口上传数据
                            uploadVideo(model);


//                            Toast.makeText(instances, "项目结束", Toast.LENGTH_LONG)
//                                    .show();
                            Handler handler = new Handler();
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    EndAllItem(String.valueOf(carsInforModel.getID()));
                                }
                            }, 1000);//后执行Runnable中的run方法

//                            Toast.makeText(instances, "项目完成", Toast.LENGTH_LONG).show();
//                            //项目总结束
//                            EndAllItem(String.valueOf(carsInforModel.getID()));
//                            updateCarStatusInfor(1);
//
//                            model.setItemcode(Item_Code);
//                            model.setLine(Line);
//                            model.setPlateNO(carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
//                            model.setPlateType(carsInforModel.getPlateType());
//                            model.setPlatformSN(carsInforModel.getPlatformSN());
//                            model.setTest_times(carsInforModel.getTimes());
//                            model.setDetectionItemStartDate(BaseApplication.D_ItemStart_time);
//                            model.setDetectionItemEndDate(BaseApplication.D_ItemEnd_time);
//                            model.setDetectionID(String.valueOf(carsInforModel.getID()));
//
//                            //视频接口上传数据
//                            uploadVideo(model);


//                            Toast.makeText(instances, "项目结束", Toast.LENGTH_LONG)
//                                    .show();
//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//
//                                }
//                            }, 300);//后执行Runnable中的run方法
                        } else {
                            CommonUtils.hideLoadingDialog(instances);
//                            Toast.makeText(instances, "项目未结束，请重试", Toast.LENGTH_LONG)
//                                    .show();
                            showDialog("底盘动态平台下线失败，请尝试重新下线");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataWaiJainEnd-onError==" + response.body());
                        String logStr = "\n" + "底盘动态结束--请求失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                ITEM_END + "\n" + "JSON::" + upjson_url_getDataWaiJainEnd + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    //上传本地后台
    private void uploadData(WaiJainDataModel waiJainDataModel) {
        Gson gson = new Gson();
        String jsonStr = gson.toJson(waiJainDataModel);
        UtilsLog.e("底盘动态--上传本地后台数据---jsonStr==" + jsonStr);
        UtilsLog.e("底盘动态--上传本地后台数据---url==" + SharedPreferencesUtils.getIP(this) + REPORTED_DATA);
        String logStr = "\n" + "底盘动态--上传本地后台数据---json" + "\n" + "json::" + jsonStr + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + REPORTED_DATA;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + REPORTED_DATA).tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("底盘动态--上传本地后台数据--result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("底盘动态--上传本地后台数据--newResult==" + newResult);
                        String logStr = "\n" + "底盘动态--上传本地后台数据---请求成功" +
                                "\n" + "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("底盘动态--上传后台数据-onError==" + response.body());
                        String logStr = "\n" + "底盘动态--上传本地后台数据--onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
//                        showDialog("上传本地后台数据网络异常，请重试");
                    }
                });
    }

    //上传平台数据
    String upjson_url_uploadPlatformData_w;

    private void uploadPlatformData_w(WaiJainDataModel waiJainDataModel) {
        Gson gson = new Gson();
        String jsonStr = gson.toJson(waiJainDataModel);
//        upjson_url_uploadPlatformData_w = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," +
//                DateUtil.codeStr2() + "}]";

        if (is_500) {
            upjson_url_uploadPlatformData_w = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," +
                    upload_code_str_500 + "}]";
        } else {
            upjson_url_uploadPlatformData_w = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "," +
                    upload_code_str + "}]";
        }
        String logStr = "\n" + "底盘动态--上传平台数据-json" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                PLAT_FORM_DATA + "\n" + "JSON::" + upjson_url_uploadPlatformData_w + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        UtilsLog.e("dipandongtai-uploadPlatformData_w---jsonStr==" + upjson_url_uploadPlatformData_w);
        UtilsLog.e("dipandongtai-uploadPlatformData_w---url==" + SharedPreferencesUtils.getIP(this) +
                PLAT_FORM_DATA);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + PLAT_FORM_DATA).tag(this)
                .upJson(upjson_url_uploadPlatformData_w)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("dipandongtai-uploadPlatformData_w-result==" + result);

//                        CommonUtils.hideLoadingDialog(instances);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("uploadPlatformData_w-newResult==" + newResult);
                        String logStr = "\n" + "底盘动态--上传平台数据-请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                PLAT_FORM_DATA + "\n" + "JSON::" + upjson_url_uploadPlatformData_w + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if ("ok".equalsIgnoreCase(newResult)) {
//                            getData(1);
                            getDataReportData("DC");
                        } else {
                            showDialog("上传平台数据失败，请重试，如果还未成功请联系管理员");
//                            Toast.makeText(instances, "项目结束失败", Toast.LENGTH_LONG)
//                                    .show();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("dipandongtai-uploadPlatformData_w-onError==" + response.body());
                        String logStr = "\n" + "底盘动态-onError-上传平台数据-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                PLAT_FORM_DATA + "\n" + "JSON::" + upjson_url_uploadPlatformData_w + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("上传平台数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    //组装要上报的json
    private String reportedJsonStr3() {
        if (TextUtils.isEmpty(BaseApplication.D_ItemStart_time) || BaseApplication.D_ItemStart_time.equals("")) {
            BaseApplication.D_ItemStart_time = DateUtil.currentTime2();
        }
        String myjson = "";
        ReportedModel codeListModel = null;
        List<ReportedModel> codeList_list = new ArrayList<>();
        if (BaseApplication.BaseApplication_buHeGeModel3List != null
                && BaseApplication.BaseApplication_buHeGeModel3List.size() > 0) {
            //去重
            Utils.removeDuplicate(BaseApplication.BaseApplication_buHeGeModel3List);

            if (BaseApplication.BaseApplication_buHeGeModel3List != null
                    && BaseApplication.BaseApplication_buHeGeModel3List.size() > 0) {
                for (int i = 0; i < BaseApplication.BaseApplication_buHeGeModel3List.size(); i++) {
                    UtilsLog.e("BaseApplication_buHeGeModel3List=去掉IsCheck==1后的数据=" +
                            BaseApplication.BaseApplication_buHeGeModel3List.toString());
                    if ("1".equals(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getIsCheck())) {
                        codeListModel = new ReportedModel();
                        codeListModel.setDataType(Item_Code);
                        codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                        codeListModel.setTest_times(carsInforModel.getTimes());
                        codeListModel.setStart_Time(BaseApplication.D_ItemStart_time);
                        codeListModel.setFinish_Time(DateUtil.currentTime2());
                        codeListModel.setWheelVerdict(dongtai_hege);
//                    codeListModel.setRemark(beizhu);
                        codeListModel.setDCResultNote(desc);
                        codeListModel.setTimes(carsInforModel.getTimes());
                        codeListModel.setWheelMaxTurn(zhuan_dong_liang);
//                        codeListModel.setWheelVerdict(dongtai_hege);
                        codeListModel.setGUID(carsInforModel.getGUID());
                        codeListModel.setUnqualified_Code1(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode1());
                        codeListModel.setUnqualified_Code2(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode2());
                        codeListModel.setUnqualified_Code3(BaseApplication.BaseApplication_buHeGeModel3List.get(i).getCode3());
                        codeList_list.add(codeListModel);
                    }
                }
                Gson gson = new Gson();
                String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
                myjson = jsonStr;
                UtilsLog.e("底盘动态--选择后的-reportedJsonStr3333==" + myjson);
            } else {
                codeListModel = new ReportedModel();
                codeListModel.setDataType(Item_Code);
                codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
                codeListModel.setTest_times(carsInforModel.getTimes());
                codeListModel.setStart_Time(BaseApplication.D_ItemStart_time);
                codeListModel.setFinish_Time(DateUtil.currentTime2());
//            codeListModel.setRemark(beizhu);
                codeListModel.setDCResultNote(desc);
                codeListModel.setGUID(carsInforModel.getGUID());
                codeListModel.setTimes(carsInforModel.getTimes());
                codeListModel.setWheelMaxTurn(zhuan_dong_liang);
                codeListModel.setWheelVerdict(dongtai_hege);
//                codeListModel.setWheelVerdict(dongtai_hege);
                codeListModel.setUnqualified_Code1("0");
                codeListModel.setUnqualified_Code2("0");
                codeListModel.setUnqualified_Code3("0");
                codeList_list.add(codeListModel);
                Gson gson = new Gson();
                String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
                myjson = jsonStr;
                UtilsLog.e("底盘动态--没有选择-reportedJsonStr4444==" + myjson);
            }
        } else {
            codeListModel = new ReportedModel();
            codeListModel.setDataType(Item_Code);
            codeListModel.setDetection_ID(String.valueOf(carsInforModel.getID()));
            codeListModel.setTest_times(carsInforModel.getTimes());
            codeListModel.setStart_Time(BaseApplication.D_ItemStart_time);
            codeListModel.setFinish_Time(DateUtil.currentTime2());
//        codeListModel.setRemark(beizhu);
            codeListModel.setGUID(carsInforModel.getGUID());
            codeListModel.setDCResultNote(desc);
            codeListModel.setTimes(carsInforModel.getTimes());
            codeListModel.setWheelMaxTurn(zhuan_dong_liang);
            codeListModel.setWheelVerdict(dongtai_hege);
//            codeListModel.setWheelVerdict(dongtai_hege);
            codeListModel.setUnqualified_Code1("0");
            codeListModel.setUnqualified_Code2("0");
            codeListModel.setUnqualified_Code3("0");
            codeList_list.add(codeListModel);
            Gson gson = new Gson();
            String jsonStr = gson.toJson(codeList_list);
//            myjson = "[{" + jsonStr.substring(1, jsonStr.length() - 1) + "}]";
            myjson = jsonStr;
            UtilsLog.e("底盘动态--默认值--reportedJsonStr555==" + myjson);
        }
        return myjson;
    }

    String myjson_getDataReportData;

    private void getDataReportData(String dateType) {
        UtilsLog.e("getDataReportData---url==" + SharedPreferencesUtils.getIP(instances) + REPORTED_DATA);
//        myjson_getDataReportData = reportedJsonStr(dateType);
        myjson_getDataReportData = reportedJsonStr3();
        UtilsLog.e("getDataReportData---json==" + myjson_getDataReportData);
        String logStr = "\n" + "底盘动态开始--JSON---" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                REPORTED_DATA + "\n" + "JSON::" + myjson_getDataReportData + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + REPORTED_DATA).tag(instances)
                .upJson(myjson_getDataReportData)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataReportData-result==" + result);
                        String logStr = "\n" + "底盘动态开始--上传自家后台请求成功" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "JSON::" + myjson_getDataReportData + "\n" +
                                "result::" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        if ("\"ok\"".equals(result)) {
                            getData(1);
                            acDipanDongtaiStart.setEnabled(false);
//                            Toast.makeText(instances, "上报数据成功", Toast.LENGTH_LONG).show();
//                            instances.finish();
                        } else {
                            CommonUtils.hideLoadingDialog(instances);
                            showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataReportData-onError==" + response.body());
                        UtilsLog.e("getDataReportData-onError==" + response.getException());
                        CommonUtils.hideLoadingDialog(instances);

                        String logStr = "\n" + "底盘动态开始--上传自家后台--失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                REPORTED_DATA + "\n" + "JSON::" + myjson_getDataReportData + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        Toast.makeText(instances, getResources().getString(R.string.services_error), Toast
//                                .LENGTH_LONG).show();

                        showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    /**
     * 项目总结束接口,最后一个执行
     */
    private void EndAllItem(final String detectionID) {
        UtilsLog.e("EndAllItem---url==" + SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                detectionID + "/DetectionID");
        OkGo.<String>get(SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                detectionID + "/DetectionID").tag(instances)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
//                        CommonUtils.hideLoadingDialog(instances);
                        String result = response.body();
                        UtilsLog.e("EndAllItem-result==" + result);
                        String logStr = "\n" + "底盘动态--总结束-成功" +
                                "\n" + "url::" + SharedPreferencesUtils.getIP(instances) + ITEM_ALL_END +
                                detectionID + "/DetectionID" + "\n" +
                                "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        Toast.makeText(instances, "项目完成", Toast.LENGTH_LONG).show();
                        mCvCountupViewTest1.stop();
                        CommonUtils.hideLoadingDialog(instances);
                        finish();
//                        if ("\"ok\"".equals(result)) {
//                            updateCarStatusInfor_anjian(1);
//                            Toast.makeText(instances, "项目完成", Toast.LENGTH_LONG).show();
//                            mCvCountupViewTest1.stop();
//                            finish();
//                        } else {
//                            showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        CommonUtils.hideLoadingDialog(instances);
                        UtilsLog.e("EndAllItem-onError==" + response.body());
                        UtilsLog.e("EndAllItem-onError==" + response.getException());
                        String logStr = "\n" + "底盘动态--总结束-失败" + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        showDialog("车辆下线失败，请重试，如果还未成功请联系管理员");
//                        Toast.makeText(instances, getResources().getString(R.string.services_error), Toast
//                                .LENGTH_LONG).show();
                    }
                });
    }

//    //拼装json  --Code2
//    private String appendCode2AndValues() {
//        String Code2JsonStr = "";
//        String result = "";
//        if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
//            for (int i = 0; i < myChoiceModelList.size(); i++) {
//                Code2JsonStr = Code2JsonStr + "\"" + myChoiceModelList.get(i).getCode_key() + "\""
//                        + ":" + "\"" + myChoiceModelList.get(i).getCode_values() + "\"" + ",";
//            }
////            UtilsLog.e("Code2JsonStr==" + Code2JsonStr);
////            UtilsLog.e("dipandongtai-Code2JsonStr=22=" + Code2JsonStr.substring(0, Code2JsonStr.length()
//// - 1));
//        }
//        if (Code2JsonStr.length() > 0) {
//            result = Code2JsonStr.substring(0, Code2JsonStr.length() - 1);
//        }
//
//        return result;
//    }

//    //获取需要检测的人工检验项目接口
//    private void getMyCarItems() {
//        ItemsModel model = new ItemsModel();
//        model.setCarType(carsInforModel.getType());
//        model.setDetectCategroy(carsInforModel.getDetectionCategory());
//        model.setPassengerNb(carsInforModel.getApprovedLoad());
//        model.setPlateType(carsInforModel.getPlateType());
//        model.setVehicleID(String.valueOf(carsInforModel.getVehicleID()));
//        String registerTime = carsInforModel.getRegisteDate();
//        String str = registerTime.substring(6, registerTime.length() - 2).trim();
//        String registerdate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
//        model.setRegisteDate(registerdate);
////        model.setRegisteDate(carsInforModel.getRegisteDate());
//        Gson gson = new Gson();
//        String json_str = gson.toJson(model);
//        UtilsLog.e("getMyCarItems---json_str==" + json_str);
//        UtilsLog.e("getMyCarItems---url==" + SharedPreferencesUtils.getIP(this) + GET_MY_ITEM);
//        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + GET_MY_ITEM).tag(this)
//                .upJson(json_str)
//                .execute(new StringCallback() {
//                    @Override
//                    public void onStart(Request<String, ? extends Request> request) {
//                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
//                    }
//
//                    @Override
//                    public void onSuccess(Response<String> response) {
//                        String result = response.body();
//                        UtilsLog.e("getMyCarItems-result==" + result);
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
//                        UtilsLog.e("getMyCarItems-newResult==" + newResult);
//                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
//                                (newResult) && !"[]".equals(result)) {
//                            List<CheckItemModel> DiPanDongTai_checkItemlList = new ArrayList<>();
////                            DiPanDongTai_checkItemlList = new ArrayList<CheckItemModel>();
//                            DiPanDongTai_checkItemlList = JsonUtil.stringToArray(newResult,
//                                    CheckItemModel[].class);
//                            mycar_checkItemlList = new ArrayList<CheckItemModel>();
////                            mycar_checkItemlList = JsonUtil.stringToArray(newResult,
////                                    CheckItemModel[].class);
//                            List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
//                            Item_2Model item_2 = null;
//                            for (int i = 0; i < DiPanDongTai_checkItemlList.size(); i++) {
//                                if (DiPanDongTai_checkItemlList.get(i).getCode1().equals("6")) {
//                                    mycar_checkItemlList.add(DiPanDongTai_checkItemlList.get(i));
//                                    item_2 = new Item_2Model();
//                                    item_2.setID(DiPanDongTai_checkItemlList.get(i).getID());
//                                    item_2.setCode1(DiPanDongTai_checkItemlList.get(i).getCode1());
//                                    item_2.setCode2(DiPanDongTai_checkItemlList.get(i).getCode2());
//                                    item_2.setName2(DiPanDongTai_checkItemlList.get(i).getName2());
//                                    Item_2Model_list.add(item_2);
//                                }
//                            }
//                            for (int i = 0; i < mycar_checkItemlList.size(); i++) {
//                                UtilsLog.e("mycar_checkItemlList-result==" + mycar_checkItemlList.get(i).toString());
//                            }
//                            for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
//                                for (int j = Item_2Model_list.size() - 1; j > k; j--) {
//                                    if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k)
//                                            .getCode2())) {
//                                        Item_2Model_list.remove(j);
//                                    }
//                                }
//                            }
//                            for (int i = 0; i < myChoiceModelList.size(); i++) {
//                                String Code2 = myChoiceModelList.get(i).getCode2().toString().trim();
//                                for (int j = 0; j < Item_2Model_list.size(); j++) {
//                                    String code2_my = Item_2Model_list.get(j).getCode2().toString().trim();
//                                    if (Code2.equals(code2_my)) {
//                                        myChoiceModelList.get(i).setCode_values("1");
//                                    }
//                                }
//                            }
//                        } else {
//                            UtilsLog.e("getGET_ALL_ITEMList-result==" + "没有数据");
//                        }
//                        CommonUtils.hideLoadingDialog(instances);
//                    }
//
//                    @Override
//                    public void onError(Response<String> response) {
//                        super.onError(response);
//                        UtilsLog.e("getMyCarItems-onError==" + response.body());
//                        CommonUtils.hideLoadingDialog(instances);
//                    }
//                });
//    }

    //获取需要检测的人工检验项目接口
    private void getMyCarItems() {
        ItemsModel model = new ItemsModel();
        model.setCarType(carsInforModel.getType());
        model.setDetectCategroy(carsInforModel.getDetectionCategory());
        model.setPassengerNb(carsInforModel.getApprovedLoad());
        model.setPlateType(carsInforModel.getPlateType());
        model.setVehicleID(String.valueOf(carsInforModel.getVehicleID()));
        String registerTime = carsInforModel.getRegisteDate();
        String str = registerTime.substring(6, registerTime.length() - 2).trim();
        String registerdate = DateUtil.getDateTimeFromMillisecond(Long.parseLong(str));
        model.setRegisteDate(registerdate);
//        model.setRegisteDate(carsInforModel.getRegisteDate());
        Gson gson = new Gson();
        String json_str = gson.toJson(model);
        UtilsLog.e("getMyCarItems---json_str==" + json_str);
        String url = "";
//        if (SharedPreferencesUtils.get38900(instances)) {
        url = GET_MY_ITEM_38900;
//        } else {
//            url = GET_MY_ITEM_;
//        }
        UtilsLog.e("getMyCarItems---url==" + SharedPreferencesUtils.getIP(this) + url);
        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + url).tag(this)
                .upJson(json_str)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getMyCarItems-result==" + result);
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("getMyCarItems-newResult==" + newResult);
                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(result)) {
                            List<CheckItemModel> DiPanDongTai_checkItemlList = new ArrayList<>();
//                            DiPanDongTai_checkItemlList = new ArrayList<CheckItemModel>();
                            DiPanDongTai_checkItemlList = JsonUtil.stringToArray(newResult,
                                    CheckItemModel[].class);
                            mycar_checkItemlList = new ArrayList<CheckItemModel>();
                            myChoiceModelList_waijian = new ArrayList<>();
//                            mycar_checkItemlList = JsonUtil.stringToArray(newResult,
//                                    CheckItemModel[].class);
                            List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
                            Item_2Model item_2 = null;
                            for (int i = 0; i < DiPanDongTai_checkItemlList.size(); i++) {
                                if (DiPanDongTai_checkItemlList.get(i).getCode1().equals("6")) {
                                    mycar_checkItemlList.add(DiPanDongTai_checkItemlList.get(i));
                                    item_2 = new Item_2Model();
                                    item_2.setID(DiPanDongTai_checkItemlList.get(i).getID());
                                    item_2.setCode1(DiPanDongTai_checkItemlList.get(i).getCode1());
                                    item_2.setCode2(DiPanDongTai_checkItemlList.get(i).getCode2());
                                    item_2.setName2(DiPanDongTai_checkItemlList.get(i).getName2());
                                    item_2.setFlag(DiPanDongTai_checkItemlList.get(i).getFlag());
                                    Item_2Model_list.add(item_2);
                                }
                            }
//                            for (int i = 0; i < mycar_checkItemlList.size(); i++) {
//                                UtilsLog.e("mycar_checkItemlList-result==" + mycar_checkItemlList.get(i).toString());
//                            }
                            for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                                for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                                    if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k)
                                            .getCode2())) {
                                        Item_2Model_list.remove(j);
                                    }
                                }
                            }
                            for (int i = 0; i < Item_2Model_list.size(); i++) {
                                MyChoiceModel model = new MyChoiceModel();
                                model.setCode2(Item_2Model_list.get(i).getCode2());
                                model.setChecked(true);
                                model.setName2(Item_2Model_list.get(i).getName2());
                                model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
                                model.setCode_values(Item_2Model_list.get(i).getFlag());
                                myChoiceModelList_waijian.add(model);
                            }

                            if (myChoiceModelList != null && myChoiceModelList.size() > 0) {
                                for (int i = 0; i < myChoiceModelList.size(); i++) {
//                                        UtilsLog.e("Code2JsonStr=22=myChoiceModelList==111111=" + myChoiceModelList.get(i).toString());
                                    String Code2 = myChoiceModelList.get(i).getCode2().toString().trim();
                                    for (int j = 0; j < Item_2Model_list.size(); j++) {
                                        String code2_my = Item_2Model_list.get(j).getCode2().toString()
                                                .trim();
                                        if (Code2.equals(code2_my)) {
                                            myChoiceModelList.get(i).setCode_values(Item_2Model_list.get(j).getFlag());
                                        }
                                    }
                                }
                            } else {
                                UtilsLog.e("myChoiceModelList=================");
                            }
                            if (myChoiceModelList_waijian != null && myChoiceModelList_waijian.size() > 0) {
                                upload_code_str = "";
                                for (int i = 0; i < myChoiceModelList_waijian.size(); i++) {
                                    upload_code_str = upload_code_str + "\"" + myChoiceModelList_waijian.get(i).getCode_key() + "\""
                                            + ":" + "\"" + myChoiceModelList_waijian.get(i).getCode_values() + "\"" + ",";
                                }
                                if (upload_code_str.length() > 0) {
                                    upload_code_str = upload_code_str.substring(0, upload_code_str.length() - 1);
                                }
                                String logStrfw = "\n" + "联网查询-外检--获取需要检测的人工检验项目接口--upload_code_str" +
                                        "\n" + "upload_code_str::" + upload_code_str;
                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrfw.getBytes());
                                UtilsLog.e("upload_code_str========" + upload_code_str);
                            } else {
                                UtilsLog.e("myChoiceModelList_waijian=================");
                            }

//                            Intent intent_2 = new Intent(instances, WaiJianResultActivity.class);
//                            intent_2.putExtra("WaiJianPhotoActivity_CarsInforModel", carsInforModel);
//                            startActivityForResult(intent_2, 500);
                        } else {
                            UtilsLog.e("getGET_ALL_ITEMList-result==" + "没有数据");
                        }
                        CommonUtils.hideLoadingDialog(instances);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getMyCarItems-onError==" + response.body());
                        CommonUtils.hideLoadingDialog(instances);
                    }
                });
    }

    //视频接口
    private void uploadVideo(VideoModel model) {
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        UtilsLog.e("uploadVideo---jsonStr==" + jsonStr);
        UtilsLog.e("uploadVideo---url==" + SharedPreferencesUtils.getIP(this) + VIDEO_ITEM);
        String logStr = "\n" + "底盘动态--uploadVideo--请求" +
                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                VIDEO_ITEM + "\n" + "JSON::" + jsonStr + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + VIDEO_ITEM).tag(this)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("uploadVideo-result==" + result);
//                        CommonUtils.hideLoadingDialog(instances);
                        String logStrf = "\n" + "底盘动态--uploadVideo--请求成功" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrf.getBytes());
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("uploadPlatformData_w-onError==" + response.body());
//                        CommonUtils.hideLoadingDialog(instances);
                        String logStr = "\n" + "底盘动态--uploadVideo-onError-失败" +
                                "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) +
                                VIDEO_ITEM + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }


    String tag = "tag";
    String PHOTO_PlatformCode = "";//拍照对应平台code


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            String logStr = "\n" + "底盘动态--返回键-屏幕底部" +
                    "\n";
            PDALogUtils.createLogFile(BaseApplication
                    .JIANCE_MODE, logStr.getBytes());

//            updateCarStatusInfor_anjian(ITEM_MIDDLE_EXIT_CODE);
            finish();
            return false;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

    AlertDialog.Builder builder = null;

    private void showDialog(String content) {
        AlertDialog.Builder builder = new AlertDialog.Builder
                (instances);
        builder.setTitle("提示");
        builder.setMessage(content);
//        builder.setNegativeButton("取消", null);
        builder.setPositiveButton("确定", null);
        builder.show();
    }

    private void showMyDialog(String[] str) {
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                UtilsLog.e("外检---showMyDialog==" + text + "===" + index);
                acVehicleDongtaiHege.setText(text);
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            switch (requestCode) {
                case 500:
                    List<CheckItemModel> list2 = (List<CheckItemModel>) data.getSerializableExtra("waiJianPhoto_buhege_List");
                    List<MyChoiceModel> waiJianPhoto_List = new ArrayList<>();//Code2选择的列表
                    if (list2 != null && list2.size() > 0) {
                        is_500 = true;
                        List<Item_2Model> Item_2Model_list = new ArrayList<>();//Code2去重后的所有数据
                        Item_2Model item_2 = null;
                        for (int i = 0; i < list2.size(); i++) {
                            item_2 = new Item_2Model();
                            item_2.setID(list2.get(i).getID());
                            item_2.setCode1(list2.get(i).getCode1());
                            item_2.setCode2(list2.get(i).getCode2());
                            item_2.setName2(list2.get(i).getName2());
                            item_2.setFlag(list2.get(i).getFlag());
                            Item_2Model_list.add(item_2);
                        }
                        for (int k = 0; k < Item_2Model_list.size() - 1; k++) {
                            for (int j = Item_2Model_list.size() - 1; j > k; j--) {
                                if (Item_2Model_list.get(j).getCode2().equals(Item_2Model_list.get(k).getCode2())) {
                                    Item_2Model_list.remove(j);
                                }
                            }
                        }

                        for (int i = 0; i < Item_2Model_list.size(); i++) {
                            MyChoiceModel model = new MyChoiceModel();
                            model.setCode2(Item_2Model_list.get(i).getCode2());
                            model.setChecked(true);
                            model.setName2(Item_2Model_list.get(i).getName2());
                            model.setCode_key("Code2-" + Item_2Model_list.get(i).getCode2());
                            model.setCode_values(Item_2Model_list.get(i).getFlag());
                            waiJianPhoto_List.add(model);
                        }
                        upload_code_str_500 = "";
                        for (int i = 0; i < waiJianPhoto_List.size(); i++) {
                            upload_code_str_500 = upload_code_str_500 + "\"" + waiJianPhoto_List.get(i).getCode_key() + "\""
                                    + ":" + "\"" + waiJianPhoto_List.get(i).getCode_values() + "\"" + ",";
                        }
                        if (upload_code_str_500.length() > 0) {
                            upload_code_str_500 = upload_code_str_500.substring(0, upload_code_str_500.length() - 1);
                        }
                        UtilsLog.e("底盘动态--list2" + list2.toString());
                        String logStrfw = "\n" + "底盘动态--onActivityResult---500---list2" +
                                "\n" + "list2::" + list2.toString() + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrfw.getBytes());
                    } else {
                        UtilsLog.e("底盘动态--list2====nulll==");
                        String logStrfw = "\n" + "底盘动态--onActivityResult---500---list2" +
                                "\n" + "list2====nulll==" + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrfw.getBytes());
                    }
                    UtilsLog.e("底盘动态--list2====upload_code_str==" + upload_code_str_500);
                    String logStrfw = "\n" + "底盘动态--onActivityResult---500---upload_code_str_500" +
                            "\n" + "upload_code_str::" + upload_code_str_500 + "\n";
//                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStrfw.getBytes());
                    break;
                case 876:
                    UtilsLog.e("手写签字上传成功--------------");
                    int result_sign = data.getIntExtra("isSign", 0);
                    if (result_sign == 1) {
                        isSign = true;
                    } else {
                        isSign = false;
                    }
                    break;
                default:
                    break;
            }

            if (resultCode == 876) {
                UtilsLog.e("手写签字上传成功--------------");
                int result_sign = data.getIntExtra("isSign", 0);
                if (result_sign == 1) {
                    isSign = true;
                } else {
                    isSign = false;
                }
            }
        }
    }

}
